﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace VideoWorld.Management
{
    /// <summary>
    /// Summary description for ManageVideoType.
    /// </summary>
    public class ManageVideoType : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataGrid dataGridVideoType;
        protected System.Web.UI.WebControls.Label LabelMessage;
        protected System.Web.UI.WebControls.TextBox textBoxName;
        protected System.Web.UI.WebControls.TextBox textBoxSummary;
        protected System.Web.UI.WebControls.Button buttonAddVideoType;
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
        protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
        protected System.Web.UI.HtmlControls.HtmlTable tableAdd;
        protected System.Web.UI.WebControls.Button buttonAdd;
        protected System.Web.UI.WebControls.Button buttonModify;
        protected System.Data.DataSet dataSetVideoType;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                tableAdd.Visible = false;
                dataGridVideoType.Visible = false;
            }
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.dataSetVideoType = new System.Data.DataSet();
            ((System.ComponentModel.ISupportInitialize)(this.dataSetVideoType)).BeginInit();
            this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
            this.buttonModify.Click += new System.EventHandler(this.buttonModify_Click);
            this.buttonAddVideoType.Click += new System.EventHandler(this.buttonAddVideoType_Click);
            this.dataGridVideoType.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dataGridVideoType_CancelCommand);
            this.dataGridVideoType.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dataGridVideoType_EditCommand);
            this.dataGridVideoType.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dataGridVideoType_UpdateCommand);
            this.dataGridVideoType.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dataGridVideoType_DeleteCommand);
            // 
            // dataSetVideoType
            // 
            this.dataSetVideoType.DataSetName = "NewDataSet";
            this.dataSetVideoType.Locale = new System.Globalization.CultureInfo("zh-CN");
            this.Load += new System.EventHandler(this.Page_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataSetVideoType)).EndInit();

        }
        #endregion
        //从数据库中取出影片类型信息
        public void SerachVideoTypeData()
        {
            dataGridVideoType.DataSource = DataAccess.Videos.SerachVideoTypeData();
            dataGridVideoType.DataKeyField = "ID";
            dataGridVideoType.DataBind();
        }
        //在DataGrid控件中进入编辑影片类型信息状态
        private void dataGridVideoType_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {

            dataGridVideoType.EditItemIndex = e.Item.ItemIndex;
            SerachVideoTypeData();
        }
        //取消在DataGrid控件中更新影片类型信息
        private void dataGridVideoType_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            dataGridVideoType.EditItemIndex = -1;
            SerachVideoTypeData();
        }
        //在DataGrid控件中删除影片类型信息
        private void dataGridVideoType_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            LabelMessage.Text = Business.Videos.DeleteVideoType(dataGridVideoType.DataKeys[e.Item.ItemIndex].ToString());
            dataGridVideoType.EditItemIndex = -1;
            SerachVideoTypeData();
        }
        //在DataGrid控件中更新影片类型信息
        private void dataGridVideoType_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            LabelMessage.Text = Business.Videos.UpdateVideoType(dataGridVideoType.DataKeys[e.Item.ItemIndex].ToString(), ((TextBox)e.Item.FindControl("textBoxName")).Text, ((TextBox)e.Item.FindControl("textBoxSummary")).Text);
            dataGridVideoType.EditItemIndex = -1;
            SerachVideoTypeData();
        }
        //添加影片类型
        private void buttonAddVideoType_Click(object sender, System.EventArgs e)
        {
            LabelMessage.Text = Business.Videos.AddVideoType(textBoxName.Text, textBoxSummary.Text);
        }
        //显示添加影片类型界面
        private void buttonAdd_Click(object sender, System.EventArgs e)
        {
            tableAdd.Visible = true;
            dataGridVideoType.Visible = false;
        }
        //显示修改更新影片类型界面
        private void buttonModify_Click(object sender, System.EventArgs e)
        {
            tableAdd.Visible = false;
            dataGridVideoType.Visible = true;
            SerachVideoTypeData();
        }
    }
}
